import type { TableColumn } from '@/components'
import { FormField } from '@/components'

export const columns: TableColumn[] = [
  {
    key: 'content',
    label: '更新内容'
  },
  {
    key: 'type',
    label: '类别',
    customRender: (e) => e.desc
  },
  {
    key: 'createTime',
    label: '更新时间',
    customRender: (e) => format(e)
  }
]

export const dialogFields: FormField[] = [
  {
    key: 'content',
    label: '更新内容',
    tag: 'ElInput',
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    key: 'type',
    label: '类别',
    tag: 'MSelect',
    attrs: {
      options: [
        {
          label: '主题1',
          value: 1
        },
        {
          label: '主题2',
          value: 2
        },
        {
          label: '主题3',
          value: 3
        }
      ]
    },
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    key: 'versionNum',
    label: '版本号',
    tag: 'ElInput',
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  }
]

//格式化时间
const format = (timestamp) => {
  const date = new Date(timestamp)
  const year = date.getUTCFullYear()
  const month = ('0' + (date.getUTCMonth() + 1)).slice(-2) // 月份是从0开始的
  const day = ('0' + date.getUTCDate()).slice(-2)
  const hours = ('0' + date.getUTCHours()).slice(-2)
  const minutes = ('0' + date.getUTCMinutes()).slice(-2)
  const seconds = ('0' + date.getUTCSeconds()).slice(-2)
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
